<template>
  <div class="frombox">
    <div class="box">
      <h1>帅帅真的C</h1>
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        class="demo-ruleForm"
      >
        <el-form-item label="账号" prop="username">
          <el-input
            type="username"
            v-model="ruleForm.username"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input
            type="password"
            v-model="ruleForm.password"
            autocomplete="off"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >登录</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data () {




    return {
      ruleForm: {
        username: 'admin',
        password: 'admin',
      },
      rules: {
        username: [
          { required: true, message: '账号不能为空', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '用户名不能为空', trigger: 'blur' }
        ],

      }
    };
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate(async (valid) => {
        console.log(valid)

        if (valid) {
          await this.$store.dispatch('user/login', this.ruleForm)
          // alert('登录成功');
          this.$router.push('/')
        } else {
          console.log('有误');
          return false;
        }
      });
    },
    resetForm (formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>
<style lang='scss'  scoped>
.frombox {
  position: absolute;
  background-color: hotpink;
  width: 100vw;
  height: 100vh;
  .box {
    width: 35%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: skyblue;
    padding: 20px 40px;
    h1 {
      text-align: center;
      color: #fff;
      font-weight: 400;
    }
  }
}
</style>
